//
//  LJCSetView.m
//  WZLProduct
//
//  Created by 陆静聪 on 16/3/23.
//  Copyright © 2016年 HaiTeng. All rights reserved.
//

#import "LJCSetView.h"

@interface LJCSetView ()

@property (nonatomic, retain) UIView *blackView;

@property (nonatomic, retain) UIButton *returnButton;
@property (nonatomic, retain) UIButton *timingButton;
@property (nonatomic, retain) UIButton *collectButton;
@property (nonatomic, assign) BOOL singleOrList;

@end


@implementation LJCSetView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
        _singleOrList = [[NSUserDefaults standardUserDefaults]boolForKey:@"singleOrList"];
        [self createView];
    }
    return self;
}

- (void)createView {
    _blackView = [[UIView alloc] init];
    [self addSubview:_blackView];
    [_blackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.offset(0);
        make.height.mas_equalTo(200);
    }];
    _blackView.backgroundColor = [UIColor blackColor];
    
    _returnButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.blackView addSubview:_returnButton];
    [_returnButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_blackView.mas_centerX);
        make.centerY.equalTo(_blackView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    [_returnButton addTarget:self action:@selector(returnAction:) forControlEvents:UIControlEventTouchUpInside];
    [_returnButton setImage:[UIImage imageNamed:@"iconfont-danquxunhuan.png"] forState:UIControlStateNormal];
    
    _collectButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.blackView addSubview:_collectButton];
    [_collectButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_blackView.mas_centerY);
        make.right.equalTo(_returnButton.mas_left).offset(-15);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    
    _timingButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.blackView addSubview:_timingButton];
    [_timingButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_blackView.mas_centerY);
        make.left.equalTo(_returnButton.mas_right).offset(15);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    [_timingButton addTarget:self action:@selector(timingAction:) forControlEvents:UIControlEventTouchUpInside];
    [_timingButton setImage:[UIImage imageNamed:@"iconfont-dingshi.png"] forState:UIControlStateNormal];
    
}

- (void)timingAction:(UIButton *)button {
    _timeBlock();
    [self removeFromSuperview];
}

- (void)returnAction:(UIButton *)button {
    _singleOrList = !_singleOrList;
    [[NSUserDefaults standardUserDefaults] setBool:_singleOrList forKey:@"singleOrList"];
    [self removeFromSuperview];
}

+ (LJCSetView *)createSetView {
    LJCSetView *setView = [[LJCSetView alloc] initWithFrame:kScreen];
    setView.alpha = 0.5;
    setView.backgroundColor = [UIColor blackColor];
    return setView;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self removeFromSuperview];
}

@end
